﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using System.Windows;

namespace Drafter.ViewModel
{

    public class InitialViewModel : ViewModelBase
    {

        #region properties
        
        /// <summary>
        /// The <see cref="LastDraftTitle" /> property's name.
        /// </summary>
        public const string LastDraftTitlePropertyName = "LastDraftTitle";

        private string _lastDraftTitle = "";

        /// <summary>
        /// Gets the LastDraftTitle property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public string LastDraftTitle
        {
            get
            {
                return _lastDraftTitle;
            }

            set
            {
                if (_lastDraftTitle == value)
                {
                    return;
                }

                var oldValue = _lastDraftTitle;
                _lastDraftTitle = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(LastDraftTitlePropertyName);

            }
        }

        #endregion


        #region commands
        public RelayCommand CloseApplicationCommand
        {
            get;
            private set;
        }

        public RelayCommand OpenFileCommand
        {
            get;
            private set;
        }

        #endregion
        /// <summary>
        /// Initializes a new instance of the InitialViewModel class.
        /// </summary>
        public InitialViewModel()
        {

            InitializeCommands();

            //if (IsInDesignMode)
            //{
                _lastDraftTitle="My Great Novel";
            //}
            //else
            //{
            //    // Code runs "for real": Connect to service, etc...
            //}
        }

        private void InitializeCommands()
        {
            CloseApplicationCommand = new RelayCommand(() =>
            {
                System.Windows.Application.Current.Shutdown();
            });

         
        }



        ////public override void Cleanup()
        ////{
        ////    // Clean own resources if needed

        ////    base.Cleanup();
        ////}
     
    }
}